package io.github.uicdb.badskill.codec;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.github.uicdb.badskill.SkillPage;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.ItemStack;

import java.util.Map;

public class JsonFactory {
    private static Gson gson;
    public static Gson create(){
        if(gson==null)
            gson=new GsonBuilder().setPrettyPrinting()
                    .registerTypeAdapter(ResourceLocation.class,ResourceLocationCodec.INSTANCE)
                    .registerTypeAdapter(ItemStack.class,ItemStackCodec.INSTANCE)
                    .registerTypeAdapter(new TypeToken<Multimap<Attribute, AttributeModifier>>(){}.getType(),AttributeMultimapCodec.INSTANCE)
                    .registerTypeAdapter(new TypeToken<Map<ResourceLocation, SkillPage.Location>>(){}.getType(),MapLocationCodec.INSTANCE)
                    .create();
        return gson;
    }
}
